<?php
// 本类由系统自动生成，仅供测试用途
namespace MyClass;
class Index extends \MyClass\Common {
   public function Index(){
		$this->s('WebsiteNum',$this->WebsiteNum());
		$this->s('bid',$this->getBid());
		$this->s('caigou',$this->caigou());
		$this->s('zbgg',$this->zbgg());
		$this->s('xjxx',$this->xjxx());
		$this->s('co',$this->co());
		$this->s('news',$this->news());
		$this->s('ComNum',$this->ComNum());
		//print_r($this->news());
			//获取这个月订单金额
		//$w['Ctime'] = array('>',mktime(0,0,0,date('m'),1,date('Y'))) ;
		//$month=$this->m('order')->where($w)->field('sum(Price)')->select();
		//$month = $month[0]['sum(Price)'];
		//$month=sprintf("%.2f", $month/100000000);
		$year=$this->m('order')->field('sum(Price)')->select();
		$year = $year[0]['sum(Price)'];
		$year=sprintf("%.2f", $year/50000000);
		$a= $this->WebsiteNum();
//		$a['CgNum'] = $a['CgNum'] + $month;
		/*if($month) {

			$a['CgNum'] = 0.9*(date('j')/10)+$month;
		} else {
			$a['CgNum'] = 0;
		}*/

		$w['Time'] = array('>',mktime(0,0,0,date('m'),1,date('Y'))) ;
		$month=$this->m('bid_order')->where($w)->field('sum(Amount)')->select();
		$month = $month[0]['sum(Amount)'];
		$m = strlen($month);
		if($m-3>=7){
			$a['CgNum'] =sprintf("%.2f", $month/100000000);
			
		}else{
			$a['CgNum'] =0.01;
		}
	    $a['ZgNum'] = 0.4*date('y')+0.08*date('m')+ $year+8;
		//采购项目数
		$bnum = $this->m('bid')->count('*');
		$inum = $this->m('inquirysheet')->count('*');
		$anum = $this->m('actinquiry')->count('*');
		$a['ZbNum'] = $bnum+ $inum+$anum+ 255;
		$this->s('WebsiteNum',$a);
		$this->v();

	}
	public function WebsiteNum(){//首页banner下数据
		$WebsiteNum = $this->m("websitenum")->where('Status = 1')->find();

		return $WebsiteNum;
	
	}
	public function ComNum(){//首页banner下数据
		$ComNum = count($this->m("user")->select());
		return $ComNum;

	}
		// 招投标
	public function getBid(){
		
		$bid = $this->m('inquirysheet i')->join("company c on i.Cid=c.Id")->field("i.*,c.CompanyName")->limit(2)->where("(i.Status = 1 OR i.Status =2) AND i.Zbtype=1")->select();
		return $bid;
	}
		// 采购
	public function caigou(){
		$caigou = $this->m('bid')->where("(Status = 1 OR Status = 2) AND Cgtype=1")->order("Pubtime desc")->limit("2")->select();
		return $caigou;
	}
	//新闻资讯
	public function news(){
		
		$news =$this->m("sys_news")->where('photo > 0')->order('creattime desc')->limit("3")->select();
		return $news;
	}
	//中标公告
	public function zbgg(){
		//招投标
		$zbgg['zb'] = $this->m('inquirysheet')->limit(1)->where("Status = 2 AND Zbtype=1")->select();
		//招标采购
		$zbgg['cg'] = $this->m('bid')->where(" Status = 2 AND Cgtype=1")->order("Pubtime desc")->limit("1")->select();
		return $zbgg;
	}
	//询价信息
	public function xjxx(){
		$xjxx = $this->m("actinquiry")->where("Ifdel = 1")->order("Pubtime DESC")->limit(2)->select();
		return $xjxx;
	}
	// 入驻企业
	public function co(){
		$co = $this->m("Company")->where("Status =1 AND id in (509,510,511) AND CompanyLogo !=''")->limit("3")->select();
		if($_SESSION['UserInfo']['id']){
			if(!isset($_SESSION['UserInfo']['cid'])){
			
				$co = $this->m("Company")->where("Status =1 AND id in (509,510,511) AND CompanyLogo !=''")->limit("3")->select();
			}else{
				$shcomp = $this->m("company")->field("Status")->where("Id=".$_SESSION['UserInfo']['cid'])->find();//查看企业是否已通过审核
				$this->s("shcomp",$shcomp);
				foreach($co as $key=>$vo){
					if(!$_SESSION['UserInfo']['cid']){
						$co[$key]["ifgb"] = 1;
					
					}else{
					$bus = $this->m("business")->where("Cid=".$_SESSION['UserInfo']['cid']." AND Gid=".$vo['Id'])->find();
						if($bus){
							$co[$key]["ifgb"] = 2;//已关注
						}else{
							$co[$key]["ifgb"] = 1;//未关注
						}
					}
				}
			}
		}
		return $co;
	}
	public function Xzurl(){
		$this->v();
	}
}